package cn.huas.util;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class LoginAdminValidateFilter implements Filter {

	public void destroy() {
	}

	public void doFilter(ServletRequest req, ServletResponse res,
			FilterChain filterChain) throws IOException, ServletException {
		/*
		 * 判断用户是否登录(即判断session中是否存在名为user的对象),如果没有登录,将用户的浏览器重定向到/user/logon.do
		 * 
		 * WebUtil.getBuyer(HttpServletRequest request)
		 */
		HttpServletRequest request = (HttpServletRequest) req;
		
		if(request.getSession().getAttribute("admin") == null){
			HttpServletResponse response = (HttpServletResponse)res;
			response.sendRedirect("/schedule/schedule/loginInfo.jsp");
			return;
		}
		filterChain.doFilter(req, res);
	}

	public void init(FilterConfig arg0) throws ServletException {
	}
}
